home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / a86v319c.zip / A13.DOC < prev    next >
Text File  |  1988-05-20  |  19KB  |  393 lines

  1. CHAPTER 13   ASSOCIATED TOOLS
  2.  
  3.  
  4. XREF Cross-reference and Symbol Listing Facility
  5.  
  6.  
  7. XREF is a tool that creates a cross-referenced symbol table
  8. listing of your program.
  9.  
  10. To invoke XREF, you must provide a program invocation line,
  11. either typed to the console when the DOS command prompt appears,
  12. or included in a batch file.  The program invocation line
  13. consists of the program name XREF, followed by the name of a .SYM
  14. symbol table file produced by A86 when you assembled your
  15. program.  You do not need to give the .SYM extension. Note that
  16. if you follow normal methodology, the name of the symbol table
  17. file is the same as the name of the program.
  18.  
  19. XREF will obtain the list of source files from the symbols file,
  20. read those source files, and create a listing file with the same
  21. name as the .SYM file, but with a .XRF extension.
  22.  
  23. Prior to V3.12, XREF required the list of source files to be
  24. explicitly given, and allowed you to specify the name of the
  25. output file.  To retain compatibility with batch files invoking
  26. the old XREF, the current version ignores anything on the command
  27. tail after the symbols file name.  This means you can no longer
  28. specify a different output file name.  Sorry about that-- I
  29. couldn't think of any other way to be compatible without
  30. overwriting somebody's source files with XREF output.  You can
  31. always rename the file after XREF is completed.
  32.  
  33. For example, you can type XREF myprog to obtain the cross-
  34. reference for the assembly that produced myprog.SYM.  The output
  35. will be in the file myprog.XRF.
  36.  
  37. The output of XREF is an alphabetical listing of all the
  38. non-local symbols in your program.  For each symbol, XREF gives
  39. its type, the file in which it was defined, its value, and a list
  40. of all procedures in which the file was used.  If you print this
  41. file, you typically use the TCOLS tool to obtain a multi-column
  42. listing from XREF's single-column output.
  43.  
  44. Note the use of procedure names to identify references -- this is
  45. unique to the A86 package, and makes the cross-reference listing
  46. truly readable.  Other cross-reference listings give either line
  47. numbers, which are meaningless unless you go find the associated
  48. line; or a file name, which doesn't give you as much useful
  49. information.
  50.  
  51. Here is a more detailed description of the various pieces of
  52. information provided for each symbol:
  53.  
  54. 1. TYPE.  Labels are indicated by a colon immediately following
  55.    the symbol name.  Special symbols such as macro names are
  56.    denoted by an appropriate word such as "macro" in place of the
  57.    value on the following line.  Other symbol types are described
  58.    by one or two characters, following the symbol name.
  59.    Possibilities for the first character are:
  60.                                                              13-2
  61.  
  62.         m  for a simple memory variable
  63.         +  for an index memory quantity
  64.         c  for a constant
  65.         i  for an interrupt-equate
  66.         s  for a structure
  67.  
  68.     If there is a second letter, it is a size attribute: b for
  69.     byte, w for word, f for far (or doubleword).
  70.  
  71. 2. FILE in which the symbol was defined.  The name is stripped of
  72.    its extension, which is presumably the same for all your
  73.    source files.  The name is preceded by = or period, which
  74.    denotes a definition of, not a reference to the symbol.
  75.  
  76. 3. VALUE, given as 4 hex digits, on the line following the
  77.    symbol.  For memory variables, this is the location of the
  78.    variable.  For indexed quantities, this is the constant-
  79.    displacement part of the quantity.  For structures, it is the
  80.    size of the structure.  For interrupt equates, it is the
  81.    number of the interrupt.
  82.  
  83. 4. REFERENCES, given on indented lines following the symbol name.
  84.    All occurrences of the symbol in your program produce a
  85.    reference.  If the symbol is the first thing on a line, it is
  86.    considered a "definition" of that symbol, the reference listed
  87.    is the source file name.  The name is preceded by a period if
  88.    the definition was via a colon (i.e., a label); it is preceded
  89.    by an equals sign otherwise. If the symbol is not the first
  90.    thing on the line, then it is not a definition.  The reference
  91.    listing consists of the name of the last definition that XREF
  92.    scanned (which, if your program is organized in a standard
  93.    way, will be the name of the procedure in which the reference
  94.    occurred.
  95.  
  96.    Observe that you must use the local-label facility of A86 to
  97.    make this work.  If you don't use local labels as your "place-
  98.    marker" symbols, the symbol XREF gives you will often be the
  99.    name of the last "place-marker" symbol, not the name of the
  100.    last procedure.
  101.  
  102.    To save space, duplicate reference entries are denoted by a
  103.    single entry, followed by "*n", where n is the decimal number
  104.    of occurrences of that entry.
  105.  
  106.  
  107. EXMAC Macro Expansion Tool
  108.  
  109. There is a tool called EXMAC which will help you troubleshoot A86
  110. program lines that call macros.  If you are not sure about what
  111. code is being generated by your macro calls, EXMAC will tell you.
  112.  
  113. To use this tool, you must first assemble your macro definitions,
  114. to produce a symbol table file.  A86 will produce a .SYM file
  115. even if there were errors.  If the errors weren't too
  116. catastrophic, the SYM file should be good enough to enable EXMAC
  117. to do its job.
  118.                                                              13-3
  119.  
  120. EXMAC can be used in two different ways.    First, it can be used
  121. as an interactive program.  You invoke the program in this way by
  122. typing just "EXMAC myprog", where myprog.SYM is the name of the
  123. symbols file.  Then you can type in any number of macro-call
  124. lines.  After each line, the program will display the expanded
  125. program text it produces.  If the program does not think your
  126. line is a macro call, it will simply echo the line back to you.
  127. In this mode, you exit the program by typing control-Z at the
  128. beginning of a line, then terminating the line with the ENTER
  129. (RETURN on some computers) key.  On most IBM-compatible
  130. computers, the control-Z code is also generated by the F6 key,
  131. for convenience.
  132.  
  133. The second way of using EXMAC is to feed a source file to it.  It
  134. will output the equivalent source file with the macros expanded.
  135. You may then, if you wish, rename the new file as the original
  136. source file, and assemble the new file.  This method is useful if
  137. you get an error on a macro expansion line, and you don't know
  138. where the error came from.   To use EXMAC in this second way, you
  139. simply redirect standard input and output: "EXMAC myprog  <infile
  140. >outfile".  With the redirection, EXMAC will take its input from
  141. the file "infile" instead of the keyboard; and it will send its
  142. output to the file "outfile" instead of the screen.  (If you are
  143. not familiar with redirection of standard input and output, you
  144. might want to read about it in Chapter 6, "Standard Input and
  145. Standard Output", of the MS-DOS reference manual.)
  146.  
  147.  
  148. A86LIB Source File Library Tool
  149.  
  150. There is a tool, A86LIB.COM, available only if you are
  151. registered, that lets you build libraries of source files.  To
  152. use A86LIB, you must first code and debug the A86 source files
  153. that you wish to include in your library.  Then you issue the
  154. command A86LIB followed by the names of the source files.
  155. Wildcards are accepted; so you will typically want to gather the
  156. source files into a single directory, and use the wildcard
  157. specification.  For example, if you use the filename extension .8
  158. for your source files, you can issue the command A86LIB *.8 to
  159. create the library.
  160.  
  161. The library created consists of a catalog file, always named
  162. A86.LIB, together with the source files that you fed to A86LIB to
  163. create the catalog.
  164.  
  165. The following observations about A86LIB are in order:
  166.  
  167. 1. Unlike object-code libraries, A86.LIB contains only symbol
  168.    names and file names; it does not contain the code itself. You
  169.    MUST retain the source files used to create A86.LIB, because
  170.    A86 will read those files that it needs after consulting
  171.    A86.LIB to read their names.
  172.  
  173. 2. A86LIB records all non-local symbols that start a line, and
  174.    are followed by a colon or an EQU.  (Recall that local symbols
  175.    are those names consisting of a single letter followed by one
  176.    or more decimal digits.)   A86LIB also records all symbols
  177.    appearing on lines starting with the word PUBLIC.
  178.                                                              13-4
  179.  
  180. 3. If a symbol appears in more than one library source file, it
  181.    will be logged for the first file A86LIB sees, and not the
  182.    subsequent ones.  No error will be reported, unless and until
  183.    A86 tries to assemble both files in one assembly, and sees a
  184.    conflict.
  185.  
  186. 4. A86LIB is simple-minded.  A86LIB does NOT recognize or expand
  187.    macros; nor does it recognize conditional-assembly directives.
  188.    This is because the library files do not stand by themselves;
  189.    the macros and conditional-assembly variables being used might
  190.    well be defined in the main program of the programs accessing
  191.    the library files.
  192.  
  193. You may update A86.LIB by running A86LIB again; either with new
  194. files or previously-recorded ones.  If A86LIB is given a file it
  195. had already read in a previous run, then A86LIB marks all the
  196. symbols it had logged for the file as deleted, before rereading
  197. the file.  Those symbols that are still in the file are then
  198. "unmarked".  Thus, symbols that have been deleted from the file
  199. disappear functionally from A86.LIB, but still occupy space
  200. within A86.LIB.  What I'm getting at is this: A86LIB will
  201. tolerate alterations in library files quite nicely; but for
  202. optimum storage efficiency you should delete A86.LIB and rebuild
  203. it from scratch any time you delete anything from the library.
  204. A86LIB is so fast that this is never very painful.
  205.  
  206.  
  207. Using A86.LIB in A86 Assemblies
  208.  
  209. Once you have created a library with A86LIB, you access it simply
  210. by calling the procedures in it from your A86 program.  When A86
  211. finishes an assembly and sees that there are undefined symbols in
  212. your program, it will automatically look for copies of A86.LIB in
  213. the current directory (then in other directories, as described in
  214. the next section).  If any of the undefined symbols are found in
  215. the A86.LIB catalog, the files containing them are assembled.
  216. You see this in the list of files output to the console by A86.
  217.  
  218. The subroutines in your library or libraries are effectively a
  219. permanent part of the A86 language.  They can be called up
  220. effortlessly in your A86 programs.  In time you can build up an
  221. impressive arsenal of library modules, making A86 as easy to
  222. program in as most high-level languages.
  223.  
  224.  
  225. Environment Variable A86LIB
  226.  
  227. You can set an environment variable A86LIB to specify which
  228. drives or subdirectories contain A86.LIB files.  The variable
  229. consists of a sequence of path names separated by semicolons,
  230. just like the PATH variable used by the operating system.  For
  231. example, if you include in your AUTOEXEC.BAT file the line
  232.  
  233.    SET A86LIB=C:\bin\lib;\tools\a86lib
  234.                                                              13-5
  235.  
  236. then A86 will look for A86.LIB in the current directory, then it
  237. will look for C:\bin\lib\A86.LIB, then \tools\a86lib\A86.LIB. A86
  238. will keep looking in all three catalog files, assembling the
  239. appropriate source files from any or all of them, until there are
  240. no more undefined symbols, or there are no more source files to
  241. assemble.
  242.  
  243. For every symbol in an A86.LIB catalog, there is recorded the
  244. name of the library file containing the symbol.  The library file
  245. is assumed to be in the same directory as its A86.LIB file,
  246. unless a complete path name (starting with \ or a drive
  247. specifier) was fed to A86.LIB when A86.LIB was created.
  248.  
  249.  
  250. Forcing a Library Search
  251.  
  252. You may force A86 to assemble library files before moving on to
  253. more of your program's source files.  You do this by placing a
  254. hash sign # (hex code 23) between file names in your invocation
  255. line.  For example, suppose your program has two modules FIRST.8
  256. and LAST.8.  FIRST.8 calls subroutines from your library; but you
  257. need the library files assembled before LAST.8 is assembled. (You
  258. might want this because LAST.8 allocates memory space beyond the
  259. end of your program, which would be the end of LAST.8 if it were
  260. truly the last module.)  You accomplish this by the invocation
  261. line:
  262.  
  263.   A86 FIRST.8 # LAST.8
  264.  
  265. Note that there is never any need to force a library search at
  266. the end of your program modules: A86 always makes a library
  267. search there, if you have any undefined symbols.
  268.  
  269.  
  270. Listings with A86
  271.  
  272. A86 does not produce a .LST file, or anything similar to it!  (We
  273. now pause, to allow traditionalists to recover from their
  274. swooning shock.)   OK, everybody back to consciousness?  Good.
  275. Now let's all try to strip away our preconceptions, and look at
  276. things with a fresh viewpoint.
  277.  
  278. In particular, let's consider what we use a listing file for, and
  279. see how A86 meets those needs.  I've been programming for 20
  280. years; I have generated literally tons of listings. Historically,
  281. here's what I have used listings for:
  282.                                                              13-6
  283.  
  284. 1. To find out what my error messages are.  In the early days of
  285.    Intel, the text editor was so bad that it was actually faster
  286.    to march across the building and physically print the list
  287.    file, than it was to use an editor to find error messages! But
  288.    even with a fast editor, what a pain it is to go into the list
  289.    file, enduring its 120-column wide format on your 80- column
  290.    screen, copy down the errors on paper, then go back to the
  291.    source file to find where the errors were.  Why doesn't the
  292.    assembler just stick the messages directly into your source
  293.    file, where you can view them and edit the source
  294.    simultaneously?  That's what A86, and only A86, does, if you
  295.    want it to.
  296.  
  297. 2. To see what code was generated; those hexadecimal bytes at the
  298.    left of the listing.  That was a real necessity, back in the
  299.    days of hexadecimal debuggers.  There we were, furiously
  300.    patching those hex object bytes.  We needed the listings to
  301.    find our way around the program, while debugging.  Today, we
  302.    have symbolic, disassembling debuggers, such as D86.  The
  303.    power of today's debuggers means that you seldom need to look
  304.    at hex object bytes.  If you do, the debugger can show them to
  305.    you.
  306.  
  307. 3. To get a symbol-table listing.  The necessity of this
  308.    diminishes a great deal when you have a SYMBOLIC debugger; but
  309.    I still like to have a listing from time to time.  So I have
  310.    devised a separate program, XREF, that goes through another
  311.    pass of the source file, and creates the world's finest cross-
  312.    reference listing for assemblers.
  313.  
  314.    You may ask, "Why am I being forced to essentially re-assemble
  315.    my code to get a symbol table, when other assemblers will give
  316.    it to me in the original assembly?"  Don't be fooled.  Those
  317.    other assemblers go through all your source files twice, or
  318.    even three times.  They just do it behind your back, every
  319.    time you want an assembly.  That's one reason why my assembler
  320.    is so much faster than everyone else's.
  321.  
  322. 4. To just look at the code.  I have often in the past needed to
  323.    see that program, spread out on paper, just to get a handle on
  324.    what the program is doing.  But I have needed this less and
  325.    less lately.  Why?  For two reasons.  First, text editors have
  326.    improved.  It's much, much easier than it was before to cruise
  327.    through a file on the screen.  Second, my programs have
  328.    adapted to the screen-viewing methodology.  Almost
  329.    subconsciously, I have started making the conceptual "chunks"
  330.    of my code fit into 1 or 2 24-line screens, rather than 1 or 2
  331.    60-line pages.  This, of course, makes better, more modular
  332.    programs.  (Spaghetti tends to untangle when you chop it up.)
  333.    It's gotten to the point where I can develop (and have
  334.    developed) a 5000-line application, fully debugged, without
  335.    ever making a listing!
  336.                                                              13-7
  337.  
  338. 5. For archival purposes.  I still do this; you should never put
  339.    100% trust in magnetic media.  But I've stripped away the
  340.    reasons for having anything but the source code and the symbol
  341.    table.  So I just copy the source files and the cross-
  342.    reference listing to the printer.  I haven't looked at the
  343.    listings too much; so I haven't bothered with pagination
  344.    control.  If you want to, you can insert form feeds into your
  345.    source; A86 will ignore them.  Or, you can write a simple
  346.    listing tool that recognizes the PAGE directive; A86 ignores
  347.    that directive, also.
  348.  
  349. As a partial remedy to those who have not been convinced by the
  350. above arguments, I now have a D86 command that sends a
  351. disassembly to a file.  The disassembly is formatted in the style
  352. of an assembler listing file, with locations and hex codes at the
  353. left.  See the D86 manual for details.
  354.  
  355.  
  356. Mimicking Tool: FAKE.EXE
  357.  
  358. As of this writing, Turbo C is aware only of the existence of
  359. Microsoft's MASM for assembling source files it generates.  I
  360. hope to persuade Borland to provide a switch to Turbo C that
  361. causes it to invoke A86 directly.  Until that happens, I offer
  362. the tool FAKE.EXE, that convinces Turbo C that A86 is really
  363. MASM.
  364.  
  365. To use FAKE.EXE, it must be renamed MASM.EXE in your disk system.
  366. I would have named it MASM myself, except that
  367.  
  368. 1. Bill Gates would probably get mad at me if I did, and
  369.  
  370. 2. You need to decide what to do with your real MASM if you have
  371.    it, before installing FAKE.  You could either place FAKE
  372.    (named MASM.EXE) into the individual directories containing
  373.    Turbo C programs, or you can rename MASM to something like
  374.    MSM.EXE or REALMASM.EXE.
  375.  
  376. Having renamed FAKE.EXE to MASM.EXE, you may now use the Turbo
  377. C's switch, -B, that allows you to place A86 statements into your
  378. C program.  You don't need to worry about the gory details of
  379. what FAKE does.
  380.  
  381. If you like gory details, here they are: FAKE filters the command
  382. line handed to it, replacing switches:
  383.  
  384.    /D becomes =
  385.    /ml becomes +c
  386.    /mx becomes +C
  387.    /E becomes +f
  388.  
  389. FAKE also eliminates the semicolon, appends .ASM to the source
  390. file name, and turns on the O and S switches.  It then feeds the
  391. resulting filtered command line to A86 for assembly.
  392.  
  393.